home *** CD-ROM | disk | FTP | other *** search
/ Sound Fx / Sound Fx.iso / Software / UNZIPED / DWSTKW / VB / VB3 / DWS.BAS next >
BASIC Source File  |  1996-07-08  |  14KB  |  328 lines

  1. '******************************************************************************
  2. ' File:      dws.bas
  3. ' Version:   1.00
  4. ' Tab stops: every 2 columns
  5. ' Project:   DiamondWare's Sound ToolKit for Windows
  6. ' Copyright: 1994-1996 DiamondWare, Ltd.  All rights reserved.
  7. ' Written:   96/03/20 by David Allen
  8. ' Purpose:   Contains declarations for the DW Sound ToolKit for Windows
  9. ' History:   96/03/28 KW & JCL finalized for 1.0
  10. '            96/04/14 JCL finalized for 1.01
  11. '            96/05/13 JCL finalized for 1.1 (no changes)
  12. '            96/05/27 JCL finalized for 1.11 (no changes)
  13. '            96/07/08 JCL finalized for 1.2 (no changes)
  14. '
  15. '*Permission is expressly granted to use this program or any derivitive made
  16. ' from it to registered users of the WIN-STK.
  17. '******************************************************************************
  18.  
  19.  
  20.  
  21. Option Explicit
  22.  
  23.  
  24. ' If a call to a dws_ function returns 0 (FALSE), then this is an
  25. ' indication that an error has occured.  Call dws_ErrNo to see which
  26. ' one.  The following series of Global Consts is the complete list of
  27. ' possible return values for dws_ErrNo.
  28. Global Const dws_EZERO = 0   ' no error
  29.  
  30.  
  31. ' The following 8 errors may be triggered by any dws_ function
  32. Global Const dws_NOTINITTED = 1
  33. Global Const dws_ALREADYINITTED = 2
  34. Global Const dws_NOTSUPPORTED = 3
  35. Global Const dws_INTERNALERROR = 4
  36. Global Const dws_INVALIDPOINTER = 5
  37. Global Const dws_RESOURCEINUSE = 6
  38. Global Const dws_MEMORYALLOCFAILED = 7
  39. Global Const dws_SETEVENTFAILED = 8
  40.  
  41. ' dws_BUSY may be triggered during a call to a dws_ function, if any
  42. ' dws_ function is already executing.  Ordinarily, this should never
  43. ' occur.
  44. Global Const dws_BUSY = 9
  45.  
  46. ' This error may be triggered only by dws_Init '
  47. Global Const dws_Init_BUFTOOSMALL = 101
  48.  
  49. ' The following 4 errors may be triggered by any dws_D (dig) function '
  50. Global Const dws_D_NOTADWD = 201
  51. Global Const dws_D_NOTSUPPORTEDVER = 202
  52. Global Const dws_D_BADDPLAY = 203
  53.  
  54. ' The following error may be triggered by dws_DPlay '
  55. Global Const dws_DPlay_NOSPACEFORSOUND = 251
  56.  
  57. ' These 2 errors may be triggered by dws_WAV2DWD '
  58. Global Const dws_WAV2DWD_NOTAWAVE = 301
  59. Global Const dws_WAV2DWD_UNSUPPORTEDFORMAT = 302
  60.  
  61. ' The following error may be triggered by any dws_M (music) function '
  62. Global Const dws_M_BADMPLAY = 401
  63.  
  64. '---------------------------------------------------------------------------'
  65. ' This section Global Consts bitfields which are used by various dws_
  66. ' functions.  Each bit in a bitfield, by definition, may be set/reset
  67. ' independantly of all other bits.
  68. '
  69.  
  70. ' flags for muscaps value of dws_DETECTRESULTS structure '
  71. Global Const dws_muscap_NONE = &H0 ' no music playback '
  72. Global Const dws_muscap_MIDIPORT = &H1 ' output port '
  73. Global Const dws_muscap_SYNTH = &H2 ' generic int synth '
  74. Global Const dws_muscap_SQSYNTH = &H4 ' square wave int synth '
  75. Global Const dws_muscap_FMSYNTH = &H8 ' FM int synth '
  76. Global Const dws_muscap_MAPPER = &H10 ' MIDI mapper '
  77. Global Const dws_muscap_ANY = &H1F ' mask of all available modes '
  78.  
  79. Global Const dws_digcap_NONE = &H0 ' no digitized sound playback '
  80. Global Const dws_digcap_11025_08_1 = &H1 ' 11kHz, 8-bit, mono '
  81. Global Const dws_digcap_11025_08_2 = &H2 ' 11kHz, 8-bit, stereo '
  82. Global Const dws_digcap_11025_16_1 = &H4 ' 11kHz, 16-bit, mono '
  83. Global Const dws_digcap_11025_16_2 = &H8 ' 11kHz, 16-bit, stereo '
  84. Global Const dws_digcap_22050_08_1 = &H10 ' 22kHz, 8-bit, mono '
  85. Global Const dws_digcap_22050_08_2 = &H20 ' 22kHz, 8-bit, stereo '
  86. Global Const dws_digcap_22050_16_1 = &H40 ' 22kHz, 16-bit, mono '
  87. Global Const dws_digcap_22050_16_2 = &H80 ' 22kHz, 16-bit, stereo '
  88. Global Const dws_digcap_44100_08_1 = &H100 ' 44kHz, 8-bit, mono '
  89. Global Const dws_digcap_44100_08_2 = &H200 ' 44kHz, 8-bit, stereo '
  90. Global Const dws_digcap_44100_16_1 = &H400 ' 44kHz, 16-bit, mono '
  91. Global Const dws_digcap_44100_16_2 = &H800 ' 44kHz, 16-bit, stereo '
  92. Global Const dws_digcap_ANY = &HFFF ' mask of all available modes '
  93.  
  94. ' The following Global Consts are bitfields used in the flags field in the
  95. ' dws_IDEAL struct.
  96. '
  97. ' SWAPLR should be used to compensate for downstream electronics which
  98. ' switch the left and right field.
  99. '
  100. ' Since pitch and volume change both require some additional CPU time,
  101. ' you may want to disable them for slow machines and enable for fast
  102. ' machines.  This is an easy way for you to do this, without changing
  103. ' your program around.
  104. '
  105. ' Notes:
  106. '   1) Pitch change is slower than volume change.
  107. '   2) Pitch decrease (dws_DPLAY.pitch > dws_IDENTITY) is slower than
  108. '      pitch increase
  109. '   3) When the source sound, or the STK, is 8-bit, raising the volume
  110. '      is slower than lowering it.  Otherwise both are equal.
  111. '
  112. Global Const dws_ideal_NONE = &H0            ' this is the normal case '
  113. Global Const dws_ideal_SWAPLR = &H1          ' swap Left & Right on playback '
  114. Global Const dws_ideal_DISABLEPITCH = &H2    ' disable the pitch feature '
  115. Global Const dws_ideal_DISABLEVOLUME = &H4   ' disable the volume feature '
  116. Global Const dws_ideal_MAXSPEED = &H6        ' use this for very slow machines '
  117.  
  118. ' These are the flag bitfields for the dws_DPLAY structure.
  119. ' Each corresponds to one field in the struct.
  120. Global Const dws_dplay_SND = &H1
  121. Global Const dws_dplay_COUNT = &H2
  122. Global Const dws_dplay_PRIORITY = &H4
  123. Global Const dws_dplay_PRESND = &H8
  124. Global Const dws_dplay_SOUNDNUM = &H10
  125. Global Const dws_dplay_LVOL = &H20
  126. Global Const dws_dplay_RVOL = &H40
  127. Global Const dws_dplay_PITCH = &H80
  128. Global Const dws_dplay_CALLBACK = &H100
  129. Global Const dws_dplay_SYNCHRONOUS = &h200
  130. Global Const dws_dplay_FIRSTSAMPLE = &h400
  131. Global Const dws_dplay_CURSAMPLE = &h800
  132. Global Const dws_dplay_LASTSAMPLE = &h1000
  133.  
  134. ' The following 2 consts indicate the status of music playback '
  135. Global Const dws_MSONGSTATUSPLAYING = &H1
  136. Global Const dws_MSONGSTATUSPAUSED = &H2
  137.  
  138.  
  139. '---------------------------------------------------------------------------'
  140. '
  141. ' When the WIN-STK sends a message to your window, the lParam field
  142. ' indicates the purpose of the message.
  143. '
  144. Global Const dws_event_SOUNDCOMPLETE = &H1
  145. Global Const dws_event_SOUNDSTARTED = &H2
  146. Global Const dws_event_SOUNDABORTED = &H3
  147.  
  148.  
  149. ' For no change in volume level or pitch '
  150. Global Const dws_IDENTITY = &H100
  151.  
  152. ' Default priority, if not specified in call to dws_DPlay '
  153. Global Const dws_NORMALPRIORITY = &H1000
  154.  
  155. '***************************************************************************
  156. 'This section declares the struct types used by the STK.  In each
  157. 'case, the user must create an instance of the struct prior to making
  158. 'a call to any STK function which takes a pointer to it.  The STK does
  159. 'not keep a pointer to any of these structs internally; after the call
  160. 'returns, you may deallocate it, if you wish.
  161. '
  162. 'NB: The STK _does_ keep pointers to digitized sound buffers!
  163. '
  164. 'A pointer to this struct is passed to dws_DetectHardWare, which fills
  165. 'it in.  It should then be passed to dws_Init.  If you plan on writing
  166. 'this struct out to a file, it's important that you write the entire
  167. 'contents.  There is information (for internal STK use only) in the
  168. 'reserved[] field!
  169.  
  170. Type type_dws_DETECTRESULTS
  171.     ' This field indicates which music capabilities are available, if any
  172.     muscaps As Long              ' see dws_muscap_xxxxxx Global Consts above
  173.  
  174.     ' This field indicates which dig capabilities are available, if any
  175.     digcaps As Long              ' see dws_digcaps_xxxxxx Global Consts above
  176.  
  177.     ' This field should be modified only with caution
  178.     digbfr As Long               ' size of buffer required by smallest capabilities
  179.  
  180.     reserved(20) As String * 1
  181. End Type
  182.  
  183. ' A pointer to this struct is passed as a parameter to dws_Init.  This
  184. ' struct allows the program to let the STK know what capabilities it
  185. ' will actually use.
  186.  
  187. Type type_dws_IDEAL
  188.     flags As Long                ' use combination of dws_ideal_xxxx
  189.     mustyp As Long               ' use dws_muscap_xxxxxx
  190.  
  191.     digtyp As Long               ' use dws_digcaps_xxxxxx (mode) to select
  192.     dignvoices As Integer        ' maximum number of mixer channels to use (16 max)
  193.  
  194.     reserved(18) As String * 1
  195. End Type
  196.  
  197. ' A pointer to this struct is passed to dws_DPlay.
  198. '
  199. ' Note that the soundnum field is filled in by dws_DPlay as a return value.
  200.  
  201. Type type_dws_DPlay
  202.     flags     As Long            ' flag word for active fields in struct
  203.     snd       As Long            ' pointer to buffer which holds a .DWD file
  204.     count     As Integer         ' number of times to play, or 0=infinite loop
  205.     priority  As Integer         ' higher numbers mean higher priority
  206.     presnd    As Integer         ' soundnum to sequence sound _after_
  207.     soundnum  As Integer         ' dws_DPlay returns a snd number from 10-65535
  208.     lvol      As Integer         ' 0-65535, 0 is off, 256 is dws_IDENTITY
  209.     rvol      As Integer         ' if the output is mono lvol & rvol are averaged
  210.     pitch     As Integer         ' 1-65535, 256 is dws_IDENTITY (0 is unuseable)
  211.     dummy     As Integer         ' added to insure DWORD alignment
  212.     
  213.     hwndmsg   As Integer         ' handle of window to which to send msg
  214.     message   As Integer         ' message number to send to hwndmsg
  215.  
  216.     firstsample As Long          ' first sample in play buffer
  217.     cursample   As Long          ' current sample in play buffer
  218.     lastsample  As Long          ' last sample in play buffer
  219.  
  220.     reserved(8) As String * 1    ' 16 bit overhead
  221. End Type
  222.  
  223. ' A pointer to this struct is passed to dws_MPlay.
  224. Type type_dws_MPlay
  225.     track As String         ' pointer to buffer which holds a null terminated .MID file name
  226.     count As Integer        ' number of times to play, or 0=infinite loop
  227.  
  228.     reserved(10) As String * 1
  229.  
  230. End Type
  231.  
  232. '***************************************************************************
  233. ' 16-bit Information/Types/Declarations
  234.  
  235. ' This function is callable at any time'  It returns the number of the
  236. ' last error which occured.
  237. Declare Function dws_ErrNo Lib "DWSW16.DLL" () As Integer
  238.  
  239. ' Each function in this section has a boolean return value'    A 0 (false)
  240. ' indicates that the function failed in some way'  In this case, call
  241. ' dws_ErrNo to get the specific error'  Otherwise, a return value of 1
  242. ' (true) indicates that all is well.
  243.  
  244. Declare Function dws_DetectHardWare Lib "DWSW16.DLL" (dws_Type As type_dws_DETECTRESULTS) As Integer
  245.  
  246. Declare Function dws_Init Lib "DWSW16.DLL" (dws_Type As type_dws_DETECTRESULTS, dws_ID As type_dws_IDEAL) As Integer
  247.  
  248. ' If the program has called dws_Init, it _MUST_ call dws_Kill before it
  249. ' terminates.
  250.  
  251. Declare Function dws_Kill Lib "DWSW16.DLL" () As Integer
  252.  
  253. ' The following function is the digital mixer of the STK.  A
  254. ' value of 0 is off; dws_IDENTITY is normal, and 0xffff is maximum
  255. ' volume (grossly distorted).
  256. Declare Function dws_XDig Lib "DWSW16.DLL" (ByVal lVolume As Integer, ByVal rVolume As Integer) As Integer
  257.  
  258. ' The following 9 functions comprise the digitized sound functions of
  259. ' the STK.  See the documentation for complete details.
  260.  
  261. Declare Function dws_DPlay Lib "DWSW16.DLL" (dws_DP As type_dws_DPlay) As Integer
  262.  
  263.     ' Allows you to change the following items:
  264.     '   count
  265.     '   priority
  266.     '   lvol
  267.     '   rvol
  268.     '   pitch
  269.     '   hwndmsg and message (simultaneously)
  270.  
  271. Declare Function dws_DSetInfo Lib "DWSW16.DLL" (dws_DP As type_dws_DPlay, dwsDP2 As Any) As Integer
  272.  
  273.     ' Can retrieve the current values for any or all of the following:
  274.     '   snd
  275.     '   count
  276.     '   priority
  277.     '   presnd
  278.     '   lvol
  279.     '   rvol
  280.     '   pitch
  281.     '   hwndmsg and message (simultaneously)
  282.  
  283. Declare Function dws_DGetInfo Lib "DWSW16.DLL" (dws_DP As type_dws_DPlay, dwsDP2 As Any) As Integer
  284.  
  285. ' Callable at any time--even before dws_Init or after dws_Kill
  286. Declare Function dws_DGetRateFromDWD Lib "DWSW16.DLL" (snd As Long, Result As Integer) As Integer
  287.  
  288. Declare Function dws_DDiscard Lib "DWSW16.DLL" (ByVal soundnum As Integer) As Integer
  289.  
  290. Declare Function dws_DDiscardAO Lib "DWSW16.DLL" (snd As Long) As Integer
  291.  
  292. Declare Function dws_DClear Lib "DWSW16.DLL" () As Integer
  293.  
  294. Declare Function dws_DPause Lib "DWSW16.DLL" () As Integer
  295.  
  296. Declare Function dws_DUnPause Lib "DWSW16.DLL" () As Integer
  297.  
  298. ' Converts a .WAV buffer to a .DWD buffer
  299. '
  300. ' This function has two usages.  In the first, pass the wave pointer, the
  301. ' wave length in *len and a NULL pointer for dwd.  The routine will return
  302. ' the length of the buffer required to hold the resulting DWD in *len.  In
  303. ' the second usage, allocate a buffer of the correct size and pass its
  304. ' address in dwd.  Make sure you pass the wave pointer in wave and the size
  305. ' of the wave in *len.  It will then perform the conversion, returning the
  306. ' number of bytes used in *len.
  307.  
  308. Declare Function dws_WAV2DWD Lib "DWSW16.DLL" (Wave As Long, Length As Long, snd As Long) As Integer
  309.  
  310. ' The following 5 functions comprise the music functions of the STK. */
  311. Declare Function dws_MPlay Lib "DWSW16.DLL" (dws_MP As type_dws_MPlay) As Integer
  312.  
  313. Declare Function dws_MSongStatus Lib "DWSW16.DLL" (Result As Integer) As Integer
  314.  
  315. Declare Function dws_MClear Lib "DWSW16.DLL" () As Integer
  316.  
  317. Declare Function dws_MPause Lib "DWSW16.DLL" () As Integer
  318.  
  319. Declare Function dws_MUnPause Lib "DWSW16.DLL" () As Integer
  320.  
  321. ' If your 16-bit application can't yield CPU time to the system, it must
  322. ' call this function periodically to prevent the sound from pausing.
  323. ' This is not required for 32-bit applications, but the function is
  324. ' supported for compatibility.
  325.  
  326. Declare Function dws_Update Lib "DWSW16.DLL" () As Integer ' Affects all sounds
  327.  
  328.